package org.ssssssss.magicapi.utils;

import freemarker.template.Configuration;

import java.io.File;
import java.io.IOException;

public class FreeMarkerUtils {

    //构造器私有化
    private FreeMarkerUtils() {}

    // 模板目录
    private static final String TEMPLATE_PATH = "magic-api/src/main/resources/template";

    private static class StaticConfigure{
        private static final Configuration CONFIGURATION = new Configuration(Configuration.VERSION_2_3_31);

    }

    // step1 创建freeMarker配置实例
    public static Configuration getConfiguration() {

        Configuration configuration = StaticConfigure.CONFIGURATION;
        try {
            configuration.setTagSyntax(Configuration.AUTO_DETECT_TAG_SYNTAX);
            // step2 获取模版路径
            configuration.setDirectoryForTemplateLoading(new File(TEMPLATE_PATH));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return configuration;
    }
}
